package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.fortune.dal.dao.CustDAO;
import com.fortune.dal.model.Cust;
import com.fortune.service.CustService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustServiceImpl implements CustService {

    @Autowired
    private CustDAO custDAO ;

    @Override
    public void addCust(Cust cust) throws BusinessException {
        try{
            custDAO.insert(cust);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCust(Cust cust) throws BusinessException {
        try{
            custDAO.updateById(cust) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public Cust queryCust(Integer custId) throws BusinessException {
        Cust c = null;
        try{
            c = custDAO.queryById(custId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public List<Cust> queryCustList(Cust cust) throws BusinessException {
        List<Cust> list = null;
        try{
            list = custDAO.queryByModel(cust) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }
}
